package com.yy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yy.mapper.UserMapper;
import com.yy.pojo.Dish;
import com.yy.pojo.User;
import com.yy.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author yyu
 * @description 针对表【t_user】的数据库操作Service实现
 * @createDate 2023-12-21 19:50:13
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
        implements UserService {

    @Autowired
    private UserMapper userMapper;


    @Override
    public IPage<User> getUsersList(int pageNum, int pageSize, User user) {
        IPage<User> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(user.getUserName())) {
            lambdaQueryWrapper.like(User::getUserName, user.getUserName());
        }

        if (StringUtils.isNotEmpty(user.getNickName())) {
            lambdaQueryWrapper.like(User::getNickName, user.getNickName());
        }

        if (StringUtils.isNotEmpty(user.getUserType())) {
            lambdaQueryWrapper.eq(User::getUserType,user.getUserType());
        }

        userMapper.selectPage(page, lambdaQueryWrapper);
        return page;
    }
    public User getByUserName(String userName) {
        return lambdaQuery().eq(User::getUserName, userName).one();
    }
}




